// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './stroe'
import Subscribe from 'we-plugins'
import UUID from 'uuid-js'
import ValiForm from '~common/plugin/ValiForm.js'
import { Notification } from 'element-ui';
import {Session} from 'we-plugins'
import 'normalize.css'
import 'flex.css'
import Mint from 'mint-ui';
import { Toast } from 'mint-ui';
import 'mint-ui/lib/style.css'
Vue.use(Mint);
Vue.config.productionTip = false
Vue.use(Subscribe);
Vue.use(Session);
Vue.prototype.$UUID=UUID
Vue.prototype.$valiForm=ValiForm.created();
Vue.prototype.$toast=Toast
Vue.prototype.$notify=Notification
window.App=new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
/* eslint-disable no-new */
router.afterEach(route => {
  if(route.meta&&route.meta.title){
    document.title=route.meta.title;
  }
});
router.beforeEach((to, from, next) => {
  if (to.meta&&to.meta.auth) {  // 判断该路由是否需要登录权限

    if (window.App&&window.App.$store.getters.user) {  // 通过vuex state获取当前的token是否存在
      console.info(window.App.$store.getters)
      next();
    }
    else {
      next({
        path: '/login',
        query: {redirect: to.name}  // 将跳转的路由path作为参数，登录成功后跳转到该路由
      });
      return
    }
  }
  else {
    next();
  }


});


